var RANDOM = '?rand=v1.0.54',
    libURL = 'http://res1.hubcloud.com.cn/';
app.config(function($stateProvider,$urlRouterProvider,$urlServiceProvider,$ocLazyLoadProvider) {
    //dsp后台管理
    var dsp = ["dspCreative","dspAdv",'dspIndex','dspAgeReport','dspRecord',"dspInfo","dspProfit","dspProfitDetail"
                    ,'dspSkuReport','dspSkuMange','dspSkuDetail','dspAgentMange'],
       //其他
        example = ["example", "reward"],
        files = {
            "modules/dsp":dsp,
            "modules/":example,
        },
        dictionary = setDictionary(files);

    /**
     * 获取modules对象
     * @param files 以文件地址前缀为键,文件名数组为值的对象
     * @returns {Array}
     */
    function setDictionary(files) {
        var dictionary = [];
        for(var path in files ) {
            angular.forEach(files[path], function (data) {
                // 拼接ocLazyLoad的modules所需对象
                var item = {};
                item.name = data;
                item.serie = true;
                item.files = [path+'/'+data + '/'+data+'.css'+RANDOM,path+'/'+data + '/'+data+'Ctrl.js'+RANDOM];
                dictionary.push(item);
            });
        }

        return dictionary;
    };
    $ocLazyLoadProvider.config({
        debug: false,
        events: false,
        modules: dictionary
    });
    var urlRules = $urlServiceProvider.rules;
    //$urlRouterProvider.when("","/list");
    urlRules.when("/dsp/report","/dsp/report/dspAgeReport");
    urlRules.when("/dsp/audit","/dsp/audit/creative");

    // urlRules.when("/","/example");
    //urlRules.otherwise("/example");
    $stateProvider
        // 例子
        .state("example",{
            url: '/example',
            templateUrl: 'modules/example/example.html'+RANDOM,
            controller: 'exampleCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'example',
                        libURL+"lib/beheCalendar/js/behe.js","css/calendar.css",
                        'js/directive.js',
                        'js/checkCalendar.js',"css/checkCalendar.css"
                    ]);
                }]
            }
        })
        // 奖励金
        .state("reward",{
            url: '/reward',
            templateUrl: 'modules/reward/reward.html'+RANDOM,
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load([
                        'reward',
                        'js/directive.js',
                        libURL+'lib/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css',
                        libURL+'lib/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js'
                    ]);
                }]
            }
        })
        //-------------------------Adhub运营后台--------------------------
        .state("dsp",{
            url: '/dsp'
        })
        // 首页
        .state("dsp.index",{
            url: '/dspIndex',
            templateUrl: 'css/dspIndex.html'+RANDOM,
            controller: 'dspIndexCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspIndex','js/directive.js', libURL+'lib/echarts/echarts.common.min.js']);
                }]
            }
        })
        // 审核管理
        .state("dsp.audit",{
            url: '/audit'
        })
        // 审核管理----------素材审核
        .state("dsp.audit.creative",{
            url: '/creative',
            templateUrl: 'modules/dsp/dspCreative/dspCreative.html'+RANDOM,
            controller: 'dspCreativeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspCreative','js/directive.js']);
                }]
            }
        })
        // 审核管理----------资质审核
        .state("dsp.audit.qualification",{
            url: '/adv',
            templateUrl: 'modules/dsp/dspAdv/dspAdv.html'+RANDOM,
            controller: 'dspAdvCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspAdv','js/directive.js']);
                }]
            }
        })
        //报表中心
        .state("dsp.report",{
            url: '/report'
        })
        // 报表中心------代理商报表
        .state("dsp.report.agent",{
            url: '/dspAgeReport',
            templateUrl: 'modules/dsp/dspAgeReport/dspAgeReport.html'+RANDOM,
            controller: 'dspAgeReportCtrl',
            resolve: {
                des: ['$ocLazyLoad', function($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspAgeReport','js/directive.js']);
                }]
            }
        })
        // 报表中心------合约资源报表
        .state("dsp.report.sku", {
            url: '/sku',
            templateUrl: 'modules/dsp/dspSkuReport/dspSkuReport.html'+RANDOM,
            controller: 'dspSkuReportCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspSkuReport', 'js/directive.js']);
                }]
            }
        })
        //合约资源
        .state("dsp.sku", {
            url: '/sku'
        })
        //合约资源管理
        .state("dsp.sku.manage", {
            url: '/manage',
            templateUrl: 'modules/dsp/dspSkuMange/dspSkuMange.html'+RANDOM,
            controller: 'dspSkuMangeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspSkuMange', 'js/directive.js']);
                }]
            }
        })
        //合约资源详情
        .state("dsp.sku.detail", {
            url: '/detail/:id',
            templateUrl: 'modules/dsp/dspSkuDetail/dspSkuDetail.html'+RANDOM,
            controller: 'dspSkuDetailCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspSkuDetail', 'js/directive.js']);
                }]
            }
        })
        //代理商管理
        .state("dsp.agent", {
            url: '/dspAgentMange',
            templateUrl: 'modules/dsp/dspAgentMange/dspAgentMange.html'+RANDOM,
            controller: 'dspAgentMangeCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspAgentMange', 'js/directive.js','js/fileUpload.js']);
                }]
            }
        })
        // 财务管理
        .state("dsp.finance", {
            url: '/finance',
        })
        // 财务记录
        .state("dsp.finance.record", {
            url: '/record',
            templateUrl: 'modules/dsp/dspRecord/dspRecord.html'+RANDOM,
            controller: 'dspRecordCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspRecord', 'js/directive.js']);
                }]
            }
        })
        // 财务信息
        .state("dsp.finance.info", {
            url: '/info',
            templateUrl: 'modules/dsp/dspInfo/dspInfo.html'+RANDOM,
            controller: 'dspInfoCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspInfo', 'js/directive.js']);
                }]
            }
        })
        // 利润提取
        .state("dsp.finance.profit", {
            url: '/profit',
            templateUrl: 'modules/dsp/dspProfit/dspProfit.html'+RANDOM,
            controller: 'dspProfitCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspProfit', 'js/directive.js']);
                }]
            }
        })
        // 利润提取
        .state("dsp.finance.profitDetail", {
            url: '/profitDetail/:id/:type',
            templateUrl: 'modules/dsp/dspProfitDetail/dspProfitDetail.html'+RANDOM,
            controller: 'dspProfitDetailCtrl',
            resolve: {
                des: ['$ocLazyLoad', function ($ocLazyLoad) {
                    return $ocLazyLoad.load(['dspProfitDetail', 'js/directive.js']);
                }]
            }
        })

})